class Enterprise < ActiveRecord::Base    
    
  validates :name, 
    :presence => true,
    :uniqueness => true
    
  belongs_to :admin, :class_name => "User", :foreign_key => "admin_id"
  has_many :users
  has_many :groups
  has_many :orders
  
  def set_admin!(user)
    update_attributes :admin_id => user.id
  end

  def users
    User.where('enterprise_id =?', id)
  end
  
  def self.current
    User.current.try(:enterprise)
  end
  
  def self.current_id
    User.current.try(:enterprise_id)
  end
  
end
